using System;

namespace OracleInternal.Common
{
	internal class RepConversion
	{
		internal static byte nibbleToHex(byte nibble)
		{
			nibble = (byte)(nibble & 0xFu);
			return (byte)((nibble < 10) ? (nibble + 48) : (nibble - 10 + 65));
		}

		internal static void bArray2nibbles(byte[] array, byte[] nibbles)
		{
			for (int i = 0; i < array.Length; i++)
			{
				nibbles[i * 2] = nibbleToHex((byte)((array[i] & 0xF0) >> 4));
				nibbles[i * 2 + 1] = nibbleToHex((byte)(array[i] & 0xFu));
			}
		}

		public static byte[] ToBinArray(string hexStr)
		{
			byte[] array = new byte[hexStr.Length / 2];
			for (int i = 0; i < hexStr.Length / 2; i++)
			{
				byte b = Convert.ToByte(hexStr.Substring(2 * i, 1), 16);
				int num = Convert.ToByte(hexStr.Substring(2 * i + 1, 1), 16) | (b << 4);
				array[i] = (byte)num;
			}
			return array;
		}

		internal static int LeftShiftFirstNibble(byte val)
		{
			return (val & 0xFF) << 24;
		}

		internal static int LeftShiftSecondNibble(byte val)
		{
			return (val & 0xFF) << 16;
		}

		internal static int LeftShiftThirdNibble(byte val)
		{
			return (val & 0xFF) << 8;
		}

		internal static int LeftShiftFourthNibble(byte val)
		{
			return val & 0xFF;
		}

		internal static byte RightShiftFirstNibble(int val)
		{
			return (byte)((uint)(val >> 24) & 0xFFu);
		}

		internal static byte RightShiftSecondNibble(int val)
		{
			return (byte)((uint)(val >> 16) & 0xFFu);
		}

		internal static byte RightShiftThirdNibble(int val)
		{
			return (byte)((uint)(val >> 8) & 0xFFu);
		}

		internal static byte RightShiftFourthNibble(int val)
		{
			return (byte)((uint)val & 0xFFu);
		}

		internal static ushort GetRegHour(byte val)
		{
			return (ushort)((val & 0x7F) << 6);
		}

		internal static byte GetRegMin(byte val)
		{
			return (byte)((val & 0xFC) >> 2);
		}
	}
}
